package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.excel.easyexcel.QuestionExcelModel;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author 东哥
 * @since 2025-10-25
 */
@Api(tags = "用户端- 问题相关接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {
    private final IInteractionQuestionService questionService;

    /**
     * 1、新增互动问题（Day5- 课堂1）
     */
    @ApiOperation("新增互动问题")
    @PostMapping
    public void saveQuestion(@RequestBody QuestionFormDTO formDTO){
        questionService.saveQuestion(formDTO);
    }

    /**
     * 2、分页查询互动问题列表（Day5- 课堂2）
     */
    @ApiOperation("分页查询互动问题列表")
    @GetMapping("page")
    public PageDTO<QuestionVO> pageQuery(QuestionPageQuery pageQuery){
        return questionService.pageQuery(pageQuery);
    }


    /**
     * 3、根据id查询问题详情（Day5- 课堂3）
     */
    @ApiOperation("根据id查询问题详情")
    @GetMapping("{id}")
    public QuestionVO queryById(@PathVariable("id") Long id){
        return questionService.queryById(id);
    }

    /**
     * 4、根据id删除当前用户问题 （Day5 - 实战1）
     * @param id
     */
    @ApiOperation("根据id删除当前用户问题")
    @DeleteMapping("/{id}")
    public void deleteQuestion(
            @ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id) {
        questionService.deleteById(id);
    }

    /**
     * 5、修改提问 （Day5 - 实战2）
     *
     * @param id
     * @param questionDTO
     */
    @ApiOperation("修改提问")
    @PutMapping("/{id}")
    public void updateQuestion(
            @ApiParam("要修改的问题的id") @PathVariable("id") Long id,
            @RequestBody QuestionFormDTO questionDTO) {
        questionService.updateQuestion(id, questionDTO);
    }

    /**
     * 批量导出问题列表 - 下载
     */
    @ApiOperation("导出")
    @GetMapping("/export")
    public void export(HttpServletResponse response, QuestionPageQuery query) throws Exception {
        //1. 获取符合条件的学员数据列表
        List<QuestionExcelModel> dataList = questionService.getExportDatas(query);
        switch (query.getExportType()){
            case 1:
                this.questionService.exportStyle1(response,dataList);
                break;
            case 2:
                this.questionService.exportStyle2(response,dataList);
                break;
            case 3:
                this.questionService.exportStyle3(response,dataList);
                break;
            case 4:
                this.questionService.exportStyle4(response,dataList);
                break;
            case 5:
                this.questionService.exportStyle5(response,dataList);
                break;
            default:
                break;
        }
    }
}
